//package com.yangye.cloud.demo.order.listener;
//
//import com.alibaba.fastjson.JSON;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.rabbitmq.client.Channel;
//import com.yangye.cloud.demo.order.domain.Event;
//import com.yangye.cloud.demo.order.enums.EventTypeEnum;
//import com.yangye.cloud.demo.order.mapper.EventMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.io.IOException;
//
///**
// * @author yangye
// * @date 2020/08/19
// */
//@Component
//@Slf4j
//public class EventListener {
//
//	@Autowired
//	private EventMapper eventMapper;
//
//	@RabbitListener(queues = "yangye-direct-queue")
//	@Transactional
//	public void consumeMsg(Message message, Channel channel) {
//		try {
//			byte[] body = message.getBody();
//			Event event = JSON.parseObject(new String(body), Event.class);
//			// 更新事件表状态为：已接受
//			event.setEventType(EventTypeEnum.RECEIVED.getCode());
//			eventMapper.insert(event);
//			// 手动ack
//			channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//			log.info("更新事件表状态为：已接受");
//		} catch (Exception e) {
//			try {
//				channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
//			} catch (IOException ioException) {
//				log.error("消息处理失败，error:", ioException.getMessage());
//			}
//
//		}
//	}
//
//}
